package com.filter.control.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class FilterServiceImpl {

    /**
     * 教学平台
     */
    @Value("${tesInit}")
    private Integer tesInit;
    /**
     * 实战仿真
     */
    @Value("${dataInit}")
    private Integer dataInit;

    /**
     * 实训平台
     */
    @Value("${trainInit}")
    private Integer trainInit;

    /**
     * 存储的map
     */
    private Map<String, Integer> map = new HashMap<>();

    public static final String TES = "tes";

    public static final String DATA = "data";

    public static final String TRAIN = "train";
    /**
     * 获取容器数量
     * @return
     */
    public Integer getContainerQuota(String key) {

        if(key.equals(TES)){
            Integer integer = map.get(TES);
            if(integer == null){
                return tesInit;
            }else{
                return integer;
            }
        }
        if(key.equals(DATA)){
            Integer integer = map.get(DATA);
            if(integer != null){
                return dataInit;
            }
        }
        if(key.equals(TRAIN)){
            Integer integer = map.get(TRAIN);
            if(integer != null){
                return trainInit;
            }
        }
        return 0;
    }


    public void saveContainerQuota(String key, Integer containerQuota) {
        map.put(key, containerQuota);
    }
}
